﻿using System;
using System.Collections.Generic;
using System.Linq;

using ZLDC.Common.Estate;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ZLDC.Topo.BLL.Estate;
namespace ZLDC.Estate.Quantify
{
    public partial class AjaxServer : System.Web.UI.Page
    {
        public string alt = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Form["alt"] == null)
            { 
                throw new Exception("错误请求！"); 
            }
            if (Request.Form["alt"].Trim().Length == 0)
            { 
                throw new Exception("错误请求！");
            }
            alt = Request.Form["alt"];
            switch (alt)
            {
                case "Reservation":
                    GetTlist();
                    break;
                case "delete":
                    delete();
                    break;
                //case "worklist":
                //    worklist();
                //    break;
                case "deptlist":
                    deptlist();
                    break;
                case "chart"://区经 总监 首页报表饼图
                    chartlist();
                    break;
                case "Determine"://套餐设置 总监 区经 设置默认套餐
                    Determine(Page);
                    break;
                case "CollectionList":
                    CollectionList();
                    break;
                case "AdminUrl"://分行经理 区经 总监 个人管理网站页面
                    AdminUrl();
                    break;
                case "GETAdminUrl"://获取管理网站
                    AdminUrl();
                    break;
                case "ReplyList":
                    ReplyList();
                    break;
                case "GetRemark"://获取个人今日意见
                    GetUserRemark();
                    break;
                case "divdatalist"://量化报表模块显示
                    GetDivdatalist();
                    break;
                case "divcharlist"://楼盘合并量化
                    divcharlist();
                    break;
                case "ForSaleList"://带看房 租 售 楼盘
                    ForSaleList();
                    break;
                case "SalePrice"://带看房 租 售 价格
                    SalePrice();
                    break;
                case "SaleArea"://带看房 租 售 面积
                    SaleArea();
                    break;
                case "ShareList"://市场占有率
                    ShareList();
                    break;
                case "cruucity"://月部门占有率
                    cruucity();
                    break;
                case "commentlist"://经理人评论 昨日 今日
                    commentlist();
                    break;
                case "deptchart"://部门占有率
                    deptchart();
                    break;
                case "area_list"://查找营业部 区域下级
                    area_list();
                    break;
                case "commentDeptList":
                    commentDeptList();//经理人评论 
                    break;
                case "Collectionhf"://收集意见 下级
                    Collectionhf();
                    break;
                case "ReplyNumber"://查询回复 未查看个人条数
                    ReplyNumber();
                    break;
                case "Collection_delete"://通用删除 参数  id  tablename
                    Collection_delete();
                    break;
                
            }
        }

       
        protected void Collection_delete()
        {
            string msg = string.Empty;
            string id = _Request.GetString("id", "0");
            string tablename = _Request.GetString("tablename", "");
            string sql = " delete "+tablename+" where id="+id+"";
           
            ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql);
            string list = "{success:true,check:true}";
            Response.Write(list);
        }

        /// <summary>
        /// 查询回复 未查看个人条数
        /// </summary>
        protected void ReplyNumber()
        {
            string msg = string.Empty;
            string sql = " select sum(see) from lp_Collection where userid="+_Utility.GetInfoBySession().m_sUserID+"";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            int i = 0;
            if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
            {
                i = int.Parse(ds.Tables[0].Rows[0][0].ToString() == "" ? "0" : ds.Tables[0].Rows[0][0].ToString());
            }
            else
            {
                i = 0;
            }
            string list = "{success:true,number:" + i + "}";
            Response.Write(list);

        }
        protected void area_list()
        {
            string parentid = _Request.GetString("parentid", "0");
            string sql = "  select id,name from t_zlhq_t_s_alldept where parent_id="+parentid+" and DltFlg=0  ";
            DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql).Tables[0];
            _Json json = new _Json(dt, 1);
            string list = "{success:true,record:" + json.ToJson() + "}";
            Response.Write(list);

            
        }
        protected void deptchart()
        {
            string startday = _Request.GetString("startday", "0");
            string endday = _Request.GetString("endday", "0");
            string c1 = _Request.GetString("c1", "");
            string c2 = _Request.GetString("c2", "");//区域
            string c3 = _Request.GetString("c3", "");//营业部
            string depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(_Utility.GetInfoBySession().m_sDeptID);//获取部门类型
            string sql = "";
            string where = " where 1=1 ";
            string file = "";
            switch (depttype)
            {
                case "营业大部":
                    sql = " select   ";
                    if (c1 == "营业部")
                    {
                        file = "ShareDepartment ";
                    }
                    if (c1 == "区域")
                    {
                        file = "sharedistrict ";
                    }
                   
                    sql += file + " as share";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    where += " and " + file + " != ''";
                    where += "  group by " + file;

                    where += " order by sum(Convert(int,sharecity)) ";
                    break;
                case "营业部":
                    sql = " select   ";
                    if (c1 == "营业部")
                    {
                        file = "ShareDepartment ";
                    }
                    if (c1 == "区域")
                    {
                        file = "sharedistrict ";
                    }
                   
                    sql += file + " as share";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    where += " and " + file + " != ''";
                    where += "  group by " + file;

                    where += " order by sum(Convert(int,sharecity)) ";
                    break;
                case "区域":
                    sql = " select   ";
                    if (c1 == "营业部")
                    {
                        file = "ShareDepartment ";
                    }
                    if (c1 == "区域")
                    {
                        file = "sharedistrict ";
                    }
                   
                    sql += file + " as share";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    where += " and " + file + " != ''";
                    where += "  group by " + file;

                    where += " order by sum(Convert(int,sharecity)) ";
                    break;
               
                default:
                    sql = " select   ";
                    if (c1 == "营业部")
                    {
                        file = "ShareDepartment ";
                    }
                    if (c1 == "区域")
                    {
                        file = "sharedistrict ";
                    }
                   
                    sql += file + " as share";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    where += " and "+file + " != ''";
                    where += "  group by "+file;
                    
                    where += " order by sum(Convert(int,sharecity)) ";
                    break;
            }
            DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql + where).Tables[0];
            _Json json = new _Json(dt, 1);
            string list = "{success:true,record:" + json.ToJson() + "}";
            Response.Write(list);
        }
        protected void commentlist()
        {
            string msg = string.Empty;
            string depttype = _Request.GetString("depttype", "0");//获取部门类型

            string deptid = _Request.GetString("deptid", "0");//获取部门ID
            if (deptid == "0")
            {
                deptid = _Utility.GetInfoBySession().m_sDeptID;
            }
            if (depttype == "0")
            {
                depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(deptid);
            }
            string deptlist = ZLDC.Common.BaseUser.UserInfo.getAllChildDept(deptid, "0");

            string sql = "select Configuration_mainID,Reply,CreateName,DeptID,lr.DeptName,lr.txtTime";
            sql += ",lr.Station,lr.CreateTime,user_name from lp_main_Reply   lr left join v_usr_link on lr.UserObj=v_usr_link.id ";

            sql += " where lr.deptid in (" + deptlist + ") and (convert(varchar,lr.txttime,23)='" + DateTime.Now.ToString("yyyy-MM-dd") + "' or convert(varchar,lr.txttime,23)='" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "')";
            sql += "order by lr.createtime desc";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            if (ds.Tables.Count > 0)
            {
                ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                msg = "{success:true,depttype:'" + depttype + "',msg:" + json.ToJson() + "}";
            }

            Response.Write(msg);
        }

        protected void commentDeptList()
        {
            string statrdate = _Request.GetString("txtstatrdate", "");
            string enddate = _Request.GetString("txtenddate", "");
            string tb = "v_lp_comment";
            string col = "ID";
            string colorder = "";
            string dept = _Request.GetString("dept", "");

            string deptid = _Utility.GetInfoBySession().m_sDeptID;
            if (dept != "")
            {
                var strlist = dept.Split('[');
                deptid = strlist[1].Substring(0, strlist[1].Length - 1);
            }
            string deptlist = ZLDC.Common.BaseUser.UserInfo.getAllChildDept(deptid, "0");
            int orderby = 1;
            string collist = "*";
            int pagesize = _Request.GetInt("pagesize", 10);
            int page = _Request.GetInt("page", 1);
            string condition = " 1=1 ";
            if (deptlist != "0")
            {
                condition += " and DeptID in (" + deptlist + ")";
            }
            if (statrdate != "")
            {
                condition += " and convert(varchar,txttime,23)>='" + statrdate + "' ";
            }
            if (enddate != "")
            {
                condition += " and convert(varchar,txttime,23)<='" + enddate + "' ";
            }
            int pages = 0;
            int intResult = 0;
           

            DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.GetTB(tb, col, colorder, orderby, collist, pagesize, page, condition, ref pages, ref intResult);
            _Json json = new _Json(dt, 1);
            string list = "{success:true,page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',pages:'" + pages + "',intResult:'" + intResult + "'},record:" + json.ToJson() + "}";
            Response.Write(list);
        }

        protected static string GetDeptXJname(string name)
        {
            string sql = "";
            sql = "select name from t_zlhq_t_s_alldept where id=(select parent_id from t_zlhq_t_s_alldept where name='"+name+"'  and DltFlg=0)";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            if (ZLDC.Topo.BLL.Estate.lp_Basis.rtcount(ds))
            {
                return ds.Tables[0].Rows[0][0].ToString();
            }
            return "";
        }


        protected void cruucity()
        {
            string startday = _Request.GetString("startday", "0");
            string endday = _Request.GetString("endday", "0");
            string sCity2 = _Request.GetString("sCity2", "");
            string sCity3 = _Request.GetString("sCity3", "");//区域
            //string department = _Request.GetString("department", "");//营业部
            //string deptid = _Utility.GetInfoBySession().m_sDeptID;
            //string currcity2text = _Request.GetString("currcity2text", "");//行政区
            //string currcity3text = _Request.GetString("currcity3text", "");//片区
            string depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(_Utility.GetInfoBySession().m_sDeptID);//获取部门类型
            string sql = "";
            string where = " where 1=1 ";
            string file = "";
            switch (depttype)
            {
                case "营业大部":
                    sql = " select  SUBSTRING(Convert(varchar,ShareDate),0,8) as ShareDate ";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    if (sCity2 != "全部")
                    {
                        where += " and ShareDepartment = '" + sCity2 + "' ";
                    }
                    if (sCity3 != "全部")
                    {
                        where += " and ShareDistrict = '" + sCity3 + "' ";
                    }
                    where += "  group by SUBSTRING(Convert(varchar,ShareDate),0,8)   order by ShareDate";
                    break;
                case "营业部":
                    sql = " select  SUBSTRING(Convert(varchar,ShareDate),0,8) as ShareDate ";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    if (sCity2 != "全部")
                    {
                        where += " and ShareDepartment = '" + sCity2 + "' ";
                    }
                    if (sCity3 != "全部")
                    {
                        where += " and ShareDistrict = '" + sCity3 + "' ";
                    }
                    where += "  group by SUBSTRING(Convert(varchar,ShareDate),0,8)   order by ShareDate";
                    break;
                case "区域":
                    sql = " select  SUBSTRING(Convert(varchar,ShareDate),0,8) as ShareDate ";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    if (sCity2 != "全部")
                    {
                        where += " and ShareDepartment = '" + sCity2 + "' ";
                    }
                    if (sCity3 != "全部")
                    {
                        where += " and ShareDistrict = '" + sCity3 + "' ";
                    }
                    where += "  group by SUBSTRING(Convert(varchar,ShareDate),0,8)   order by ShareDate";
                    break;
              
                default:
                    sql = " select  SUBSTRING(Convert(varchar,ShareDate),0,8) as ShareDate ";
                    sql += " ,sum(Convert(int,sharecompany)) as sharecompany,sum(Convert(int,sharecity)) as number  from lp_Share ";

                    if (startday != "0")
                    {
                        where += " and ShareDate>='" + startday + "-01' ";
                    }
                    if (endday != "0")
                    {
                        where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1).ToString("yyyy-MM") + "-01' ";
                    }
                    if (sCity2 != "全部")
                    {
                        where += " and ShareDepartment = '"+sCity2+"' ";
                    }
                    if (sCity3 != "全部")
                    {
                        where += " and ShareDistrict = '" + sCity3 + "' ";
                    }
                    where += "  group by SUBSTRING(Convert(varchar,ShareDate),0,8)   order by ShareDate";
                    break;
            }
            DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql + where).Tables[0];
            _Json json = new _Json(dt, 1);
            string list = "{success:true,record:" + json.ToJson() + "}";
            Response.Write(list);
        }


        //@tb varchar(50), --表名 
        //@col varchar(50), --按该列来进行分页(必须是唯一性的字符，比如标识种子) 
        //@colorder varchar(50), --需要排序的字段(为空，则默认为col) 
        //@orderby bit, --排序,0-顺序,1-倒序 
        //@collist varchar(800),--要查询出的字段列表,*表示全部字段 
        //@pagesize int, --每页记录数 
        //@page int, --指定页 
        //@condition varchar(2800),--查询条件 
        //@pages int OUTPUT --总页数
        //--@sqlout nvarchar(4000),---返回sql语句
        protected void ShareList()
        {
            string startday = _Request.GetString("startday", "0");
            string endday = _Request.GetString("endday", "0");
            string ename = _Request.GetString("ename", "");
            string district = _Request.GetString("district", "");
            string department = _Request.GetString("department", "");
            string deptname = _Utility.GetInfoBySession().m_sDeptName;

            string tb = "lp_Share";
            string col = "ID";
            string colorder = "";

            int orderby = 1;
            string collist = " CONVERT(varchar(7),ShareDate,120) as ShareDate,*";
            int pagesize = _Request.GetInt("pagesize", 10);
            int page = _Request.GetInt("page", 1);

            string sql = "select top 15 * from (select  sharename,sum(Convert(int,ShareCompany)) ShareCompany ,sum(Convert(int,ShareCity))  ShareCity from lp_Share ";
            string where = " where 1=1 ";
            if (startday != "0")
            {
                where += " and ShareDate>='" + startday + "-01' ";
            }
            if (endday != "0")
            {
               where += " and ShareDate<'" + Convert.ToDateTime(endday).AddMonths(1) + "-01' ";
            }
            if (ename != "")
            {
                where += " and ShareName='" + ename + "' ";
            }
            if (district != "")
            {
                where += " and sharedistrict='" + district + "' ";
            }
            if (department != "")
            {
                where += " and department like '" + department + "%' ";
            }
            where += "  group by ShareName ) t order by ShareCity desc ";

            //DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql );
            string msg = string.Empty;

            //if (ds.Tables.Count > 0)
            //{
            //    ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
            //    msg = "{success:true,msg:" + json.ToJson() + "}";
            //}
            //Response.Write(msg);

            int pages = 0;
            int intResult = 0;

            //DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.GetTB(tb, col, colorder, orderby, collist, pagesize, page, where, ref pages, ref intResult);
            DataTable dt =ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql+where).Tables[0];
            _Json json = new _Json(dt, 1);
            string list = "{success:true,page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',pages:'" + pages + "',intResult:'" + intResult + "'},record:" + json.ToJson() + "}";
            Response.Write(list);
        }

        protected void SaleArea()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            //string type = _Request.GetString("type", "0");
            //string deptid = _Request.GetString("detpid", "0");
            //string addDate2 = _Request.GetString("EndTime", "");
            //string addDate1 = _Request.GetString("startTime", "");


            string StratTime = _Request.GetString("startTime", "");
            string EndTIME = _Request.GetString("EndTime", "");
            string deptId = _Request.GetString("deptid", _Utility.GetInfoBySession().m_sDeptID);
            string rdvalue = _Request.GetString("rdvalue", "");//楼盘 价格 面积
            //string USERID = _Request.GetString("UserName", "");
            string ftype = _Request.GetString("type");     // 'all' 表示查询所有客源跟进，包括系统本身的  '带看房'
            // '' 空表示查询 '电话沟通','面谈','带看租房','带看售房','其它方式'

            // 非空表示查询某个分类的数据           
            if (StratTime == "" && EndTIME == "")
            {
                StratTime = DateTime.Now.ToString("yyyy-MM-dd");

                EndTIME = DateTime.Now.ToString("yyyy-MM-dd");
            }

            string IdList1 = "";//下级部门
            if (_Convert.ToInt(deptId.ToString()) > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptId);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }
            string condition = "   1=1 ";
            string station = _Utility.GetInfoBySession().m_sStation;
            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源跟进"))//系统管理员查看全部
            {
                if (IdList1 != "")
                {
                    condition += " and fdeptid in(" + IdList1 + ") ";
                }
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))//经理级以上查询下级部门所有跟进
                {
                    string IdList = CacheUtility.Cache_GetAllChildDept(deptId);

                    if (deptId != "")
                    {
                        condition += " and fdeptid in(" + IdList1 + ") and fdeptid in(" + IdList + ") ";
                    }
                    else
                    {
                        condition += " and fdeptid in(" + IdList + ") ";
                    }

                }
                else
                {
                    condition += " and fUserId=" + _Utility.GetInfoBySession().m_sUserID + "";
                }

            }

            if (StratTime != "" && EndTIME != "")
            {
                //condition += "  and fdate between '" + StratTime + " 00:00:00" + "' and '" + EndTIME + " 23:59:59" + "' ";
                condition += "  and Convert(varchar,fdate,23) >= '" + Convert.ToDateTime(StratTime).ToString("yyyy-MM-dd") + "" + "' and  Convert(varchar,fdate,23)<='" + Convert.ToDateTime(EndTIME).ToString("yyyy-MM-dd") + "" + "' ";
            }



            // 带看售房 带看租房 待看提醒...
            if (!ftype.Equals("all"))
            {
                if (!ftype.Equals(""))
                {
                    if (ftype.Equals("带看房"))
                    {
                        condition += " and ftype in ('带看租房','带看售房')";
                    }
                    else
                    {
                        condition += " and ftype='" + ftype + "'";
                    }
                }
                else
                {
                    string typeList = "";
                    DataTable dtParam = SystemParamBLL.ListByType("跟进方式(客)");
                    for (int i = 0; i < dtParam.Rows.Count; i++)
                    {

                        string itemName = dtParam.Rows[i]["item"].ToString();
                        if (itemName == "带看房")
                        {
                            typeList += "'带看租房','带看售房',";
                        }
                        else
                        {
                            typeList += "'" + itemName + "',";
                        }

                    }
                    if (typeList != "")
                    {
                        typeList = typeList.Substring(0, typeList.Length - 1);
                    }

                    condition += " and ftype in (" + typeList + ")";
                }
            }
            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.lp_Area(condition, ftype, rdvalue);
            Response.Write(json);
        }
        protected void SalePrice()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            //string type = _Request.GetString("type", "0");
            //string deptid = _Request.GetString("detpid", "0");
            //string addDate2 = _Request.GetString("EndTime", "");
            //string addDate1 = _Request.GetString("startTime", "");


            string StratTime = _Request.GetString("startTime", "");
            string EndTIME = _Request.GetString("EndTime", "");
            string deptId = _Request.GetString("deptid", _Utility.GetInfoBySession().m_sDeptID);
            string rdvalue = _Request.GetString("rdvalue", "");//楼盘 价格 面积
            //string USERID = _Request.GetString("UserName", "");
            string ftype = _Request.GetString("type");     // 'all' 表示查询所有客源跟进，包括系统本身的  '带看房'
            // '' 空表示查询 '电话沟通','面谈','带看租房','带看售房','其它方式'

            // 非空表示查询某个分类的数据           
            if (StratTime == "" && EndTIME == "")
            {
                StratTime = DateTime.Now.ToString("yyyy-MM-dd");

                EndTIME = DateTime.Now.ToString("yyyy-MM-dd");
            }

            string IdList1 = "";//下级部门
            if (_Convert.ToInt(deptId.ToString()) > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptId);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }
            string condition = "   1=1 ";
            string station = _Utility.GetInfoBySession().m_sStation;
            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源跟进"))//系统管理员查看全部
            {
                if (IdList1 != "")
                {
                    condition += " and fdeptid in(" + IdList1 + ") ";
                }
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))//经理级以上查询下级部门所有跟进
                {
                    string IdList = CacheUtility.Cache_GetAllChildDept(deptId);

                    if (deptId != "")
                    {
                        condition += " and fdeptid in(" + IdList1 + ") and fdeptid in(" + IdList + ") ";
                    }
                    else
                    {
                        condition += " and fdeptid in(" + IdList + ") ";
                    }

                }
                else
                {
                    condition += " and fUserId=" + _Utility.GetInfoBySession().m_sUserID + "";
                }

            }

            if (StratTime != "" && EndTIME != "")
            {
                //condition += "  and fdate between '" + StratTime + " 00:00:00" + "' and '" + EndTIME + " 23:59:59" + "' ";
                condition += "  and Convert(varchar,fdate,23) >= '" + Convert.ToDateTime(StratTime).ToString("yyyy-MM-dd") + "" + "' and  Convert(varchar,fdate,23)<='" + Convert.ToDateTime(EndTIME).ToString("yyyy-MM-dd") + "" + "' ";
            }

          

            // 带看售房 带看租房 待看提醒...
            if (!ftype.Equals("all"))
            {
                if (!ftype.Equals(""))
                {
                    if (ftype.Equals("带看房"))
                    {
                        condition += " and ftype in ('带看租房','带看售房')";
                    }
                    else
                    {
                        condition += " and ftype='" + ftype + "'";
                    }
                }
                else
                {
                    string typeList = "";
                    DataTable dtParam = SystemParamBLL.ListByType("跟进方式(客)");
                    for (int i = 0; i < dtParam.Rows.Count; i++)
                    {

                        string itemName = dtParam.Rows[i]["item"].ToString();
                        if (itemName == "带看房")
                        {
                            typeList += "'带看租房','带看售房',";
                        }
                        else
                        {
                            typeList += "'" + itemName + "',";
                        }

                    }
                    if (typeList != "")
                    {
                        typeList = typeList.Substring(0, typeList.Length - 1);
                    }

                    condition += " and ftype in (" + typeList + ")";
                }
            }
            string json = ZLDC.Topo.BLL.Estate.CustomerBLL.lp_salecount(condition, ftype, rdvalue);
            Response.Write(json);
        }
        protected void ForSaleList()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
           //string type = _Request.GetString("type", "0");
           //string deptid = _Request.GetString("detpid", "0");
           //string addDate2 = _Request.GetString("EndTime", "");
           //string addDate1 = _Request.GetString("startTime", "");
            string depttype = _Request.GetString("hiddepttype", "");//1为分行经理 查询
           
           string StratTime = _Request.GetString("startTime", "");
           string EndTIME = _Request.GetString("EndTime", "");
           string deptId = _Request.GetString("deptid", _Utility.GetInfoBySession().m_sDeptID);
           string rdvalue = _Request.GetString("rdvalue", "");//楼盘 价格 面积
           //string USERID = _Request.GetString("UserName", "");
           string ftype = _Request.GetString("type");     // 'all' 表示查询所有客源跟进，包括系统本身的  '带看房'
           // '' 空表示查询 '电话沟通','面谈','带看租房','带看售房','其它方式'

           // 非空表示查询某个分类的数据           
           if (StratTime == "" && EndTIME == "")
           {
               StratTime = DateTime.Now.ToString("yyyy-MM-dd");

               EndTIME = DateTime.Now.ToString("yyyy-MM-dd");
           }

           string IdList1 = "";//下级部门
           if (_Convert.ToInt(deptId.ToString()) > 0)
           {
               DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptId);
               for (int i = 0; i < dt.Rows.Count; i++)
               {
                   if (dt.Rows[i]["id"].ToString() != "")
                   {
                       IdList1 += dt.Rows[i]["id"].ToString() + ",";
                   }
               }
               if (IdList1 != "")
               {
                   IdList1 = IdList1.Substring(0, IdList1.Length - 1);
               }
           }
           string condition = "  where 1=1 ";
           string condition_1 = "   where 1=1 ";
           string station = _Utility.GetInfoBySession().m_sStation;
           if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部客源跟进"))//系统管理员查看全部
           {
               if (IdList1 != "")
               {
                   condition += " and fdeptid in(" + IdList1 + ") ";
               }
           }
           else
           {
               if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))//经理级以上查询下级部门所有跟进
               {
                   string IdList = CacheUtility.Cache_GetAllChildDept(deptId);

                   if (deptId != "")
                   {
                       condition += " and fdeptid in(" + IdList1 + ") and fdeptid in(" + IdList + ") ";
                   }
                   else
                   {
                       condition += " and fdeptid in(" + IdList + ") ";
                   }

               }
               else
               {
                   string IdList = CacheUtility.Cache_GetAllChildDept(deptId);

                   if (deptId != "")
                   {
                       condition += " and fdeptid in(" + IdList1 + ") and fdeptid in(" + IdList + ") ";
                   }
                   else
                   {
                       condition += " and fdeptid in(" + IdList + ") ";
                   }
                   //condition += " and fUserId=" + _Utility.GetInfoBySession().m_sUserID + "";
               }

           }

           if (StratTime != "" && EndTIME != "")
           {
               //condition += "  and fdate between '" + StratTime + " 00:00:00" + "' and '" + EndTIME + " 23:59:59" + "' ";
               condition += "  and fdate >= '" + Convert.ToDateTime(StratTime).ToString("yyyy-MM-dd") + "" + "' and  fdate<='" + Convert.ToDateTime(EndTIME).ToString("yyyy-MM-dd") + "" + "' ";
               condition_1 += "  and fdate >= '" + Convert.ToDateTime(StratTime).ToString("yyyy-MM-dd") + "" + "' and  fdate<='" + Convert.ToDateTime(EndTIME).ToString("yyyy-MM-dd") + "" + "' ";

           }

           //if (_Convert.ToInt(USERID, 0) > 0)
           //    condition += " AND fUserId='" + USERID + "' ";
           //else
           //{

           //    if (USERID != "")
           //    {
           //        string userName = string.Empty; // 姓名
           //        string userNo = string.Empty;   // 工号
           //        int userId = 0;                 // 楼盘系统用户ID
           //        _Utility.GetUserNoAndUserName(USERID.Trim(), out userName, out userNo);
           //        if (userName == "")
           //        {
           //            condition += " AND fUserId='" + USERID + "' ";
           //        }
           //        else
           //        {
           //            userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);//如果姓名不等于空，取楼盘系统用户表ID

           //            condition += " AND fUserId='" + userId.ToString() + "' ";
           //        }
           //    }
           //}

           // 带看售房 带看租房 待看提醒...
           if (!ftype.Equals("all"))
           {
               if (!ftype.Equals(""))
               {
                   if (ftype.Equals("带看房"))
                   {
                       condition += " and ftype in ('带看租房','带看售房')";
                       condition_1 += " and ftype in ('带看租房','带看售房')";
                   }
                   else
                   {
                       condition += " and ftype='" + ftype + "'";
                       condition_1 += " and ftype='" + ftype + "'";
                   }
               }
               else
               {
                   string typeList = "";
                   DataTable dtParam = SystemParamBLL.ListByType("跟进方式(客)");
                   for (int i = 0; i < dtParam.Rows.Count; i++)
                   {

                       string itemName = dtParam.Rows[i]["item"].ToString();
                       if (itemName == "带看房")
                       {
                           typeList += "'带看租房','带看售房',";
                       }
                       else
                       {
                           typeList += "'" + itemName + "',";
                       }

                   }
                   if (typeList != "")
                   {
                       typeList = typeList.Substring(0, typeList.Length - 1);
                   }

                   condition += " and ftype in (" + typeList + ")";
                   condition_1 += " and ftype in (" + typeList + ")";
               }
           }

           string groupbyfiled = " ";//分组
           string showfiled = "a.*";//需要显示的字段
           string orderbyfiled = " count desc";//排序的
           string json = ZLDC.Topo.BLL.Estate.CustomerBLL.lp_CustomerfollowReport_list_table(page, pagesize, condition, condition_1, ftype, rdvalue, groupbyfiled, showfiled, orderbyfiled, depttype);
           Response.Write(json);
         
        }


        /// <summary>
        /// 套餐设置 总监 区经 设置默认套餐 1为生效0为取消
        /// </summary>
        /// <param name="p"></param>
        protected void Determine(System.Web.UI.Page p)
        {
            string msg = string.Empty;
            string userid = _Request.GetString("userid", "0");
            string deptid = _Request.GetString("deptid", "0");
            string type = _Request.GetString("type","");
            string sql = "" ;
            switch (type)
            {
                case "1":
                    sql = "update lp_Package set Other4='1' where CreateUser=" + userid + "";
                    break;
                case "0":
                    sql = "update lp_Package set Other4='0' where CreateUser=" + userid + "";
                    break;
            }
            
            int i=ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql);
            msg = "{success:true,msg:" + type + "}";
            Response.Write(msg);
        }

        public void chartlist()
        {
            string msg = string.Empty;
            string depttype = _Request.GetString("depttype", "0");//获取部门类型
            string deptid = _Request.GetString("deptid", "0");//获取部门类型
            if (deptid == "0")
            {
                deptid = _Utility.GetInfoBySession().m_sDeptID;
            }
            if (depttype == "0")
            {
                depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(deptid);
            }
            string sql = "select BasisName,SUM(Actual_Goal) as Actual_Goal,sum(Actual_Number) as Actual_Number from lp_Configuration ";
            string sqlwhere = " where CONVERT(varchar,CreateTime,23)='" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'  and (Actual_Goal>0 or Actual_Number>0)";
            switch (depttype)
            {
                case "营业大部":
                    sqlwhere += " and Other8='" + deptid + "' ";
                    break;
                case "营业部":
                    sqlwhere += " and Other6='" + deptid + "' ";
                    break;
                case "区域":
                    sqlwhere += " and Other4='" + deptid + "' ";
                    break;
            }

            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql + sqlwhere + " group by BasisName");
            if (ds.Tables.Count > 0)
            {
                ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                msg = "{success:true,depttype:'" + depttype + "',msg:" + json.ToJson() + "}";
            }
            Response.Write(msg);
        }










        /// <summary>
        /// 查询 经理是否昨日 前日检查工作，未达标人员，未工作部署人员，工作点评
        /// </summary>
        public void deptlist()
        {
           
            string msg = string.Empty;
            string depttype = _Request.GetString("depttype", "0");//获取部门类型

            string deptid = _Request.GetString("deptid", "0");//获取部门类型
            if (deptid == "0")
            {
                deptid = _Utility.GetInfoBySession().m_sDeptID;
            }
            if (depttype == "0")
            {
                depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(deptid);
            }
            if (depttype == "营业大部" || depttype == "营业部" || depttype == "区域")
            {
                string sql = " select * from lp_worklist where work_deptid in (  select Id from t_zlhq_t_s_alldept where parent_id=" + deptid + " and DltFlg=0) and work_daytime='" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'";
                //string sql = " select * from lp_worklist where work_deptid in (  select Id from t_zlhq_t_s_alldept where parent_id="+deptid+") and work_daytime='2012-04-20'";
                DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
                if (ds.Tables.Count > 0)
                {
                    ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                    msg = "{success:true,depttype:'" + depttype + "',msg:" + json.ToJson() + "}";
                }
            }
            else
            {
                bool Assignment = true;// ZLDC.Project.CommonLib.PageManager.CurrentUserInfo.GetPopedom("查看营业部");//是否有查看营业部数据的权限
                if (Assignment)
                {
                    string sql = " select * from lp_worklist where work_deptid in (SELECT id FROM t_zlhq_t_s_alldept t where DltFlg=0 and  fgs='"+ZLDC.Topo.BLL.Estate.lp_Basis.GetArea()+"' and type='营业部' ) and work_daytime='" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'";

                    DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
                    if (ds.Tables.Count > 0)
                    {
                        ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                        msg = "{success:true,depttype:'" + depttype + "',msg:" + json.ToJson() + "}";
                    }
                }
            }
            Response.Write(msg);
        }



       
        /// <summary>
        /// 删除预约日期的工作
        /// </summary>
        public void delete()
        {
            string time = _Request.GetString("time","0");
            string deptid = _Request.GetString("deptid", "0");
            string sql = " delete from lp_Configuration_main where workday='"+time+"' and deptid="+deptid+";";
            sql += " delete from lp_Configuration where CONVERT(varchar,createtime,23)='"+time+"' and Other2='"+deptid+"'";
            ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql);
            GetTlist();
        }
        /// <summary>
        /// 部门查询 预约工作日期
        /// </summary>
        public void GetTlist()
        {
            string msg = string.Empty;
            //string sql = "select * from lp_Configuration_main where workDay>CONVERT(varchar,GETDATE(),23) and deptid="+_Utility.GetInfoBySession().m_sDeptID+"";
            string sql = "select workDay,deptID from lp_Configuration_main where  deptid=" + _Utility.GetInfoBySession().m_sDeptID + " and workDay>CONVERT(varchar,GETDATE(),23) group by workDay,deptID";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            if (ds.Tables.Count > 0)
            {
                ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                msg = "{success:true,msg:" + json.ToJson() + "}";
                
            }
            Response.Write(msg);
            //string msg = "{success:true,msg:'1'}";
            //Response.Write(msg);
        }

        /// <summary>
        /// 查询意见收集 回复
        /// </summary>
        public void Collectionhf()
        {
            string msg = string.Empty;
            string mainid = _Request.GetString("mainid", "0");
            string type = _Request.GetString("type", "0");

            string sql ="";
            if (type == "0")
            {
                sql = "update lp_Collection set see=(case when (see<=0) then 0 else (see-1) end) where id=" + mainid + " and userid=" + _Utility.GetInfoBySession().m_sUserID + "; select * from lp_Collection where mainid=" + mainid;
            }
            else
            {
                sql = "select * from lp_Collection where mainid=" + mainid;
            }
                DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            if (ds.Tables.Count > 0)
            {
                ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                msg = "{success:true,msg:" + json.ToJson() + "}";

            }
            Response.Write(msg);
        }


        //@tb varchar(50), --表名 
        //@col varchar(50), --按该列来进行分页(必须是唯一性的字符，比如标识种子) 
        //@colorder varchar(50), --需要排序的字段(为空，则默认为col) 
        //@orderby bit, --排序,0-顺序,1-倒序 
        //@collist varchar(800),--要查询出的字段列表,*表示全部字段 
        //@pagesize int, --每页记录数 
        //@page int, --指定页 
        //@condition varchar(2800),--查询条件 
        //@pages int OUTPUT --总页数
        //--@sqlout nvarchar(4000),---返回sql语句
        public void CollectionList()
        {
            string deptid = _Request.GetString("deptid", "0");
            string type = _Request.GetString("type", "");
            string statrdate = _Request.GetString("txtstatrdate", "");
            string enddate = _Request.GetString("txtenddate", "");
            string tb = "lp_Collection";
            string col = "ID";
            string colorder = "collectiontop desc, CreateTime";
           
            int orderby = 1;
            string collist = "*";
            int pagesize = _Request.GetInt("pagesize", 10);
            int page = _Request.GetInt("page",1);
            string condition = " 1=1 and mainid=0 ";
             if (deptid != "0")
            {
                condition += " and DeptID="+deptid+"";
            }
             if (statrdate != "")
             {
                 condition += " and convert(varchar,CreateTime,23)>='" + statrdate + "' ";
             }
             if (enddate != "")
             {
                 condition += " and convert(varchar,CreateTime,23)<='" + enddate + "' ";
             }
             if (type == "1")
             {
                 condition += " and userid="+_Utility.GetInfoBySession().m_sUserID+" ";
             }
            int pages = 0;
            int intResult = 0;

            DataTable dt = ZLDC.Topo.BLL.Estate.lp_Basis.GetTB(tb, col, colorder, orderby, collist, pagesize, page, condition, ref pages, ref intResult);
            _Json json = new _Json(dt, 1);
            string list = "{success:true,page:{currentpage:'" + page + "',pagesize:'" + pagesize + "',pages:'" + pages + "',intResult:'" + intResult + "'},record:" + json.ToJson() + "}";
            Response.Write(list);
        }

        public void AdminUrl()
        {
            string msg = string.Empty;
            string userid = _Request.GetString("userid",_Utility.GetInfoBySession().m_sUserID);
            string where = " where UserID="+userid;
            string sql = "select * from lp_WorkUrl"+where ;
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
                ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                msg = "{success:true,msg:" + json.ToJson() + "}";
            Response.Write(msg);
        }


        /// <summary>
        /// 插入意见表，返回主表记录
        /// </summary>
        public void ReplyList()
        {
            string msg = string.Empty;
            string userid = _Request.GetString("userid","0");
            int mainid = _Request.GetInt("mainid",0);
            string txttime = _Request.GetString("txttime","0");
            string txtremark = _Request.GetString("txtremark","");
            int type = _Request.GetInt("type",0);
            if (type == 1)
            {
                if(txtremark!=""){
                string sql = "insert into lp_main_Reply (Configuration_mainID,Reply,MainID,DeptID,DeptName,Station,CreateTime,CreateName,txtTime,CreateUserid,UserObj) "
                            + " values ("
                            + " " + mainid + ",'" + txtremark + "',0," + _Utility.GetInfoBySession().m_sDeptID + ",'" + _Utility.GetInfoBySession().m_sDeptName + "',"
                            + " '" + _Utility.GetInfoBySession().m_sStation + "' , '" + DateTime.Now + "','" + _Utility.GetInfoBySession().m_sUserName + "','"+txttime+"',"+_Utility.GetInfoBySession().m_sUserID+","+userid+""
                            + ");";
                ZLDC.Topo.BLL.Estate.lp_Basis.Execution_sql(sql);
                GetReplyList(mainid, msg);}
            }
            if (type == 0)
            {
                GetReplyList(mainid, msg);
            }
            
        }

        /// <summary>
        /// 查询意见表 意见
        /// </summary>
        /// <param name="mainid"></param>
        /// <param name="msg"></param>
        public void GetReplyList(int mainid,string msg)
        {
            string sql = "select * from lp_main_Reply where Configuration_mainID=" + mainid + " order by createtime desc";
            DataSet ds=ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
            msg = "{success:true,msg:" + json.ToJson() + "}";
            Response.Write(msg);
        }

        /// <summary>
        /// 查询个人今日意见
        /// </summary>
        public void GetUserRemark()
        {
            string msg = string.Empty;
            string userid = _Request.GetString("userid", "0");
            int mainid = _Request.GetInt("mainid", 0);
            string workday = _Request.GetString("workday", "0");
            string sql = "select * from lp_main_Reply where Configuration_mainID=" + mainid + " and UserObj=" + userid + " and CreateUserID=" + _Utility.GetInfoBySession().m_sUserID + " and txtTime='" + Convert.ToDateTime(workday).ToString("yyyy-MM-dd") + "' order by createtime desc";
            DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql);
            //ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
            if(ds.Tables[0].Rows.Count>0)
            msg = "{success:true,msg:" + ds.Tables[0].Rows[0]["Reply"].ToString() + "}";
            Response.Write(msg);
        }


        public void GetDivdatalist()
        {
           
            string deptid = _Request.GetString("deptid", "0");
            string statrday = _Request.GetString("statrday", "0");
            string endday = _Request.GetString("endday", "0");
            string depttype = _Request.GetString("depttype", "0");//获取部门类型
            GetTB(deptid,statrday,endday,depttype);
        }
        /// <summary>
        /// 页面查询显示条件，身份不同查询不同
        /// </summary>
        /// <param name="deptId"></param>
        /// <param name="startdate"></param>
        /// <param name="enddate"></param>
        protected void GetTB(string deptId, string startdate, string enddate,string depttype)
        {
            #region
            string msg = string.Empty;
            string newsql = "";//重新sql


            string sqlfile = "select SUM(total) as total,SUM(Actual_Goal) as Actual_Goal ";
            string sql = "   where 1=1 ";
            string group = "group by   ";
            string sqlwhere = " where 1=1 "; //饼图显示条件
            StringBuilder sb = new StringBuilder();
          
          
            if (depttype == "分行")
            {

                sqlfile += ",userid,user_name,id ";
                sql += " and id=" + deptId + "";
                sqlwhere += "and Other2=" + deptId + "";
                group += "userid,user_name,id order by total desc";

            }
            else
            {
                newsql = "select sum(work_Actual_Goal)as Actual_Goal,work_deptname ,work_deptid  from lp_worklist where work_deptid in (select id as deptid from t_zlhq_t_s_alldept where parent_id=" + deptId + " and DltFlg=0)"
                                      + "and work_daytime >=" + startdate + " and work_daytime<=" + enddate + " "
                                      + "group by   work_deptid,work_deptname order by Actual_Goal desc";
            }
           
            sqlfile += " from v_lp_mainlist";
            sql = sqlfile + sql;
            sql += " and workday >=" + startdate + " and workday<=" + enddate + " ";
            DataSet ds = new DataSet();
            if (depttype == "分行")
                ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(sql + group);
            else {
                ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(newsql);
            }
            ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
           
            msg = "{success:true,msg:" + json.ToJson() + "}";
            Response.Write(msg);
            #endregion
            //GetCharts(myNext, ZLDC.Topo.BLL.Estate.lp_Report_list.GetSql(sqlwhere, statrday, enddate));
        }

        /// <summary>
        /// 楼盘与量化合并页面
        /// </summary>
        public void divcharlist()
        {
            
            string deptid = _Request.GetString("deptid", _Utility.GetInfoBySession().m_sDeptID);
            string statrday = _Request.GetString("statrday", DateTime.Now.ToString("yyyy-MM-dd"));
            string endday = _Request.GetString("endday", DateTime.Now.ToString("yyyy-MM-dd"));
            string depttype = ZLDC.Topo.BLL.Estate.lp_Report_list.GetType(deptid);//获取部门类型
            if (ViewState.Count == 0)
            {
                GetTableCount(deptid);
            }
            GetCharlist(deptid, statrday, endday, depttype);
        }

        /// <summary>
        /// 页面查询显示条件，身份不同查询不同
        /// </summary>
        /// <param name="deptId"></param>
        /// <param name="startdate"></param>
        /// <param name="enddate"></param>
        protected void GetCharlist(string deptId, string startdate, string enddate,string depttype)
        {
            string msg = string.Empty;
            string sqlwhere = " where 1=1 "; //饼图显示条件
            switch (depttype)
            {
                case "营业大部":
                    sqlwhere += "and Other8='" + deptId + "'";
                    break;
                case "营业部":
                    sqlwhere += "and Other6='" + deptId + "'";
                    break;
                case "区域":
                    sqlwhere += "and Other4='" + deptId + "'";
                    break;
                case "分行":
                    sqlwhere += "and Other2=" + deptId + "";
                    break;
                default:
                    sqlwhere = "";
                    break;
            }
            if (sqlwhere != "")
            {
                DataSet ds = ZLDC.Topo.BLL.Estate.lp_Basis.Getds(ZLDC.Topo.BLL.Estate.lp_Report_list.GetSql(sqlwhere, "'" + startdate + "'", "'" + enddate + "'"));
                ZLDC.Common.Estate._Json json = new _Json(ds.Tables[0]);
                msg = "{success:true,deptid:" + deptId + ",msg:" + json.ToJson() + "}";

            }
            else
            {
                msg = "{success:true,deptid:" + deptId + ",msg:''}";
                
            }
            Response.Write(msg);
        }
        /// <summary>
        /// 查询点击分行 是否有权限
        /// </summary>
        protected void GetTableCount(string deptid)
        {

            if (int.Parse(ZLDC.Topo.BLL.Estate.lp_Report_list.GetTableCount(deptid)) > 0)
            {
                ViewState["tbcount"] = "1";
            }

        }
    }
}
